<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>我的购买</title>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__CSS__/public.min.css">
    <style>
        a.list-item:active {
            background-color: #fff;
        }

        .btn_copy {
            border: 1px solid #00a4ff;
            color: #00a4ff;
            padding: 0 5px;
        }
    </style>
</head>
<body ontouchstart>
<div class="page">
    <div class="header">
        <div class="header__hd">
            <a class="iconfont mb-mobile-back"></a>
        </div>
        <h1 class="header__title">我的购买<span class="header__subtitle"></span></h1>
        <div class="header__ft">
            <a id="js-delete" href="javascript:">删除</a>
        </div>
    </div>
    <div class="page__bd">
        <div class="list" id="js-list"></div>
    </div>
</div>
<script id="tpl" type="text/html">
    <% for(i = 0; i < list.length; i++){ %>
    <a class="list-item list-purchase-item mb7" href="javascript:">
        <div class="list-item__delete">
            <i class="iconfont delete" data-id="<%= list[i].id %>"></i>
        </div>
        <div class="list-item__content">
            <div class="list-item__hd">
                <div class="cell">
                    <div class="cell__bd">
                        <div class="cell__title">
                            <b><%= list[i].title %></b>
                        </div>
                    </div>
                    <div class="cell__ft">
                        <span class="text--primary">
                            <% if (list[i].state == 1) { %>支付成功<% } else { %>支付失败<% } %>
                        </span>
                    </div>
                </div>
            </div>
            <div class="list-item__bd">
                <div class="cell">
                    <div class="cell__bd">
                        <% if (list[i].vip_exp_date) { %>
                        <div class="cell__text">有效期：<%= $imports.format(list[i].endTime * 1000, "yyyy-MM-dd") %>至<%= $imports.format(list[i].vip_exp_date, "yyyy-MM-dd") %></div>
                        <% } %>
                        <div class="cell__text">支付时间：<%= $imports.format(list[i].createTime * 1000, "yyyy-MM-dd h:mm") %></div>
                        <div class="cell__text">数量：<%= list[i].good_num %></div>
                        <div class="cell__text">支付方式：
                            <% if (list[i].pay_type == 1) { %>
                            微信
                            <% } else if (list[i].pay_type == 2) { %>
                            支付宝
                            <% } else { %>
                            G币
                            <% } %>
                        </div>
                    </div>
                    <% if (list[i].pay_state == 1) { %>
                    <div class="cell__ft">
                        <div class="btn btn--plain_muted" data-group_id="<%= list[i].group_id %>">
                            <span class="btn__inner">续费</span>
                        </div>
                    </div>
                    <% } %>
                </div>
            </div>
            <div class="list-item__ft">
                <span>订单号：<%= list[i].orderNo %></span>
                <span class="btn_copy" data-str="<%= list[i].orderNo %>">复制</span>
                <span class="text-black">
                    <% if (list[i].pay_type == 3) { %>
                    共计：<span class="f14"><%= list[i].tag %></span>G币
                    <% } else { %>
                    共计：￥<span class="f14"><%= list[i].money %></span>
                    <% } %>
                </span>
            </div>
        </div>
    </a>
    <% } %>
</script>
<script src="__JS__/jquery.min.js"></script>
<script src="__JS__/template-web.js"></script>
<script src="__JS__/common.js?v={$Think.config.commonJs}"></script>
<script>
    template.defaults.imports.format = function (date, format) {
        if (date == "") {
            date = new Date();
        } else {
            date = new Date(date);
        }
        var map = {
            "M": date.getMonth() + 1, //月份
            "d": date.getDate(), //日
            "h": date.getHours(), //小时
            "m": date.getMinutes(), //分
            "s": date.getSeconds(), //秒
            "q": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds() //毫秒
        };
        format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
            var v = map[t];
            if (v !== undefined) {
                if (all.length > 1) {
                    v = '0' + v;
                    v = v.substr(v.length - 2);
                }
                return v;
            } else if (t === 'y') {
                return (date.getFullYear() + '').substr(4 - all.length);
            }
            return all;
        });
        return format;
    };

    // 点击header删除按钮，列表显示删除按钮
    $('#js-delete').on('click', function () {
        var $list = $('#js-list'),
            isActive = $list.hasClass('list--delete');

        if (isActive) {
            $(this).html('删除');
            $list.removeClass('list--delete')
        } else {
            $(this).html('完成');
            $list.addClass('list--delete')
        }
    });

    var list = {$order_list};
    if (list.length == 0) {
        $('.page__bd').html('<div class="blank"><div class="blank__text-area"><div class="blank__title">空空如也，漫漫人生很无聊</div></div></div>');
    } else {
        $('#js-list').html(template('tpl', {list: list}));
    }

    $("#js-list").on('click', '.delete', function () {
        var that = $(this);
        var $parent = $(this).parent().parent();

        var $dialog = utils.dialog({
            content: '您确定要删除购买记录吗？',
            buttons: [{
                label: '取消',
                type: 'default',
                onClick: function () {
                    $dialog.hide();
                }
            }, {
                label: '确定',
                type: 'primary',
                onClick: function () {
                    $.ajax({
                        url: '/my_order_del',
                        type: "PUT",
                        dataType: "json",
                        data: {id: that.data('id')},
                        success: function (res) {
                            if (res.code == 200) {
                                $parent.remove();
                                //如果删除光了 显示
                            } else {
                                alert(res.msg)
                            }
                        }
                    });
                }
            }]
        });
    });

    $("#js-list").on('click', '.btn--plain_muted', function () {
        window.open('/group_go_pay?group_id=' + $(this).data('group_id'));
    });

    $("#js-list").on('click', '.btn_copy', function () {
        var str = $(this).data('str');
        window.android._copy(str + " ");
    });
</script>
</body>
</html>